<?php

class Adept_Template_Attribute_Expression extends Adept_Template_Attribute_Abstract
{

    /**
     * @var Adept_Template_Expression_Abstract
     */
    protected $expression;

    public function __construct($expression)
    {
        $this->expression = $expression;
    }

    public function transformExpression($source)
    {
        $expression = preg_replace("/\.([\w]+)/", "['\\1']", $source);
        $expression = preg_replace('/\$(\w+)/', '$context[\'\\1\']', $expression);
        return $expression;
    }
    
    public function generate($writer)
    {
        $writer->writePhp($this->transformExpression($this->expression->makeExpression()));
    }

    public function generateBindingString($writer)
    {
        $writer->writePhpLiteral($this->expression->makeExpression());
    }
    
    public function getValue() 
    {
        return null;    
    }
        
    public function setValue($value) 
    {
        
    }

}
